﻿@using Vit.Common.Collections;
@model IEnumerable<TreeNode<NavigationItem>>
@{
    Layout = Theme.Layout("_AdminDialog");
    ViewDataDictionary viewData = new ViewDataDictionary();
    Func<dynamic, object> itemTemplate = @<text><input type="checkbox" id="cb_@(item.Key)" name="cb_@(item.Key)" value="@item.Value" onclick="ToggleCheck(this);" @(item.Selected ? "checked" : "") /><span>@item.Caption</span></text>;
    viewData["ItemTemplate"] = itemTemplate;
}
<script type="text/javascript">
    function ToggleCheck(ele) {
        if (ele.checked) {
            $(ele).parent().find('input:checkbox').attr('checked', 'checked');
            $(ele).parents('li').children('input:checkbox').attr('checked', 'checked');
            $(ele).parents('.tree').first().find('input:checkbox[value=' + $(ele).val() + ']').attr('checked', 'checked');
        }
        else {
            $(ele).parent().find('input:checkbox').removeAttr('checked');
            $(ele).parents('.tree').first().find('input:checkbox[value=' + $(ele).val() + ']').removeAttr('checked');
        }
    }
</script>
@{ Html.BeginForm(null, null, FormMethod.Post, new { id = "list-form", name = "list-form" }); }
<div class="tree">
    @Html.Partial("_TreeView", this.Model, viewData)
</div>
@{ Html.EndForm(); }
